<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../js/global.js"></script>
		<script src="../js/checked.js"></script>
	</head>
	<body>
		<form id="formCreateUser" class="layui-form" action="" onsubmit="return false">
			<div class="layui-form-item" style="margin-top: 30px;">
				<label class="layui-form-label"><span style="color: red;">*</span>考场批次:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" placeholder="请输入考场批次" name="addressSequence"
						lay-verify="uname" class="layui-input" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>考试批次:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" placeholder="请输入考试批次" name="examSequence"
						 class="layui-input" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>使用时长:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" placeholder="请输入使用时长" name="useTime"
						 class="layui-input" />
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>考场:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<select class="ex" name="examRoomId">
						<option></option>
					</select>
				</div>
			</div>
			
			
			<div class="layui-btn-container" style="text-align: center;">
				<button class="layui-btn" lay-submit="" lay-filter="addUser">添加</button>
			</div>
		</form>
		<script>
			layui.use(['form','layer'],function(){
				var $=layui.$,
				form=layui.form,
				layer=layui.layer;
				//渲染用户表
				$.get(globalData.examinationServer + '/examRoom/listExamRooms', function(res) {
					var html = "";
					for (var i = 0; i < res.data.length; i++) {
						html += "<option value=" + res.data[i].examRoomId + ">" + res.data[i].examRoomNo + "</option>"
				
					}
					$(".ex").append(html);
				
					form.render('select')
				}, "json")
				
				//添加按钮提交监听
				
				form.on('submit(addUser)',function(obj){
					//var str=$("#formCreateUser").serialize();
					//console.log(obj.field);
					$.ajax({
						type : "post",
						url : globalData.examinationServer+'/sequence/insertSequence',
						data:obj.field,//需要传递到服务端的数据
						dataType:'json',//服务端响应数据类型
						xhrFields: {
							withCredentials: true
						},
						// beforeSend: function(request) {
						// 	request.setRequestHeader("token", globalData.getCurToken());
						// },
						success : function(res) {
							if(res.code == 0){
									layer.msg('添加成功',{icon:1,time:2000},function(index){
										layer.close(index);
										//关闭父窗口并重载
										dkm._close();
										dkm._reload();
									});
									
								}else{
									layer.msg('添加失败',{icon:2,time:2000});
							}
						}
					});
					
					return false;
				});
				
				
			});
		</script>
	</body>
</html>
